// run: time -p $exec < input
#include <iostream>
#include <string>

int n, m;
int c[100];
int cc[100];
int count = 0;

bool square(std::string const& s)
{
	int len = s.size();
	if (len & 1) return false;
	return s.substr(0, len / 2) == s.substr(len / 2, len / 2);
}

bool judge(std::string const& s)
{
	std::string t;
	for (auto ch : s) {
		t += ch;
		if (square(t)) return false;
	}
	return true;
}

bool judge2(std::string const& s)
{
	int len = s.size();
	if (!(len & 1)) return false;
	return s.substr(0, len / 2) == s.substr(len / 2 + 1, len / 2);
}

void dfs(std::string const& s, int d)
{
	if (d) {
		int t = judge(s);
		count += t;
		c[d] += t;
		if (d & 1 && t) cc[d] += judge2(s);
	}
	if (d == n) return;
	for (int i = 0; i < m; i++)
		dfs(s + char('a' + i), d + 1);
}

int main()
{
	while (std::cin >> n >> m) {
		dfs("", 0);
		std::cout << count << ' ';
		std::cout << '\n';
		for (int i = 1; i <= n; i++) std::cout << c[i] << ' ';
		std::cout << '\n';
		for (int i = 1; i <= n; i += 2) std::cout << cc[i] << ' ';
		std::cout << '\n';
		return 0;
	}
}

